{
LANG : PASCAL
PROB : palsquare
}

program PALSQUARE;
const
  fi = 'palsquare.in';
  fo = 'palsquare.out';
type
  num = record
          l : integer;
          d : array[1..100] of byte;
        end;
var
  base : integer;

procedure getstr(k : longint; var sk : num);
begin
  with sk do
  begin
    l := 0;
    while k > 0 do
    begin
      inc(l);
      d[l] := k mod base;
      k := k div base;
    end;
  end;
end;

function palin(sk : num) : boolean;
var
  i : integer;
begin
  palin := false;
  with sk do
    for i := 1 to l div 2 do
      if d[i] <> d[l-i+1] then exit;
  palin := true;
end;

procedure out(sk : num);
var
  i : integer;
begin
  with sk do
    for i := l downto 1 do
      if d[i] <= 9 then write(d[i])
      else write(chr(d[i]-9+64));
end;

procedure process;
var
  i, j : longint;
  si, sj : num;
begin
  for i := 1 to 300 do
  begin
    j := sqr(i);
    getstr(i, si);
    getstr(j, sj);
    if palin(sj) then
    begin
      out(si);
      write(' ');
      out(sj);
      writeln;
    end;
  end;
end;

begin
  assign(input, fi); reset(input);
  assign(output, fo); rewrite(output);
  read(base);
  process;
  close(output);
  close(input);
end.